/*
 * @Author: Miakit
 * @Date: 2025-05-04 22:36:49
 * @LastEditors: [Miakit]
 * @LastEditTime: 2025-05-15 12:33:02
 * @FilePath: \org_finance_vue\src\utils\index.ts
 * @Description: 
 */
type TargetContext = '_self' | '_parent' | '_blank' | '_top';

export const openWindow = (
  url: string,
  opts?: { target?: TargetContext; [key: string]: any }
) => {
  const { target = '_blank', ...others } = opts || {};
  window.open(
    url,
    target,
    Object.entries(others)
      .reduce((preValue: string[], curValue) => {
        const [key, value] = curValue;
        return [...preValue, `${key}=${value}`];
      }, [])
      .join(',')
  );
};

/**
 * 区间生成对比符号
 * @param between 
 * @returns 
 */
export const makeBetweenString = (between: string)=>{
  between = between.replace(/\s/g, '')
  let [ star, end ] = between.split(',')
  if(!star || !end){ return '' }
  if(star == '0' && end !== 'max'){ return `&lt;${end}`}
  if(star !== '0' && end == 'max'){ return `&#8805;${star}`}
  if(star !== '0' && end !== 'max'){ return `${star}-${end}`}
}


export const regexUrl = new RegExp(
  '^(?!mailto:)(?:(?:http|https|ftp)://)(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$',
  'i'
);

export default null;
